package com.softer.chengxin.score.dao.provider;

import com.softer.chengxin.score.entity.ScoreComposite;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author Gong Zhiyang
 * @date 2018/10/12
 */
public class ScoreManagerDaoProvider {
    public String getScoreList(Map<String, ScoreComposite> map){
        StringBuilder sql = new StringBuilder(6);
        sql.append("SELECT a.id,a.basic_score AS basicScore,a.excellent_score AS excellentScore,a.negative_score AS negativeScore,a.`level`,");
        sql.append("a.all_score AS allScore,a.company_id AS companyId,a.`year`,b.`name` AS qyName,b.business_license_no AS businessLicenseNo ");
        sql.append("FROM score_composite a LEFT JOIN company_base_info b ON a.company_id = b.id");
        sql.append(" WHERE a.company_id=#{sc.companyId}");
        commonSql(sql,map);
        return sql.toString();
    }
    /**
     * 查询省平台推送的综合情况
     * @param map 查询map
     * @return SQL
     */
    public String getScoreListFromProvince(Map<String, ScoreComposite> map){
        StringBuilder sql = new StringBuilder(6);
        sql.append("SELECT a.id,a.basic_score AS basicScore,a.excellent_score AS excellentScore,a.negative_score AS negativeScore,a.`level`,");
        sql.append("a.all_score AS allScore,a.company_id AS companyId,a.`year`,b.`name` AS qyName,b.business_license_no AS businessLicenseNo ");
        sql.append("FROM score_composite_province a LEFT JOIN company_base_info b ON a.company_id = b.guid");
        sql.append(" WHERE b.id=#{sc.companyId}");
        commonSql(sql,map);
        return sql.toString();
    }
    private void commonSql( StringBuilder sql,Map<String, ScoreComposite> map){
        ScoreComposite scoreComposite = map.get("sc");
        if (StringUtils.isNotBlank(scoreComposite.getLevel())) {
            sql.append(" AND a.level=#{sc.level} ");
        }
        if (StringUtils.isNotBlank(scoreComposite.getYear())) {
            sql.append(" AND a.`year`=#{sc.year}");
        }
    }
}
